--
-- Author: shunguo.chen
-- Date: 2018-03-19 18:39:33
--
-- ChessHeadIconRender  谜棋头像icon render
--

local HeadRender = require("app.widget.renders.HeadRender")

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node)
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--data = CosplayRole
function ClassRef:init(data)
    self.super.init(self, data)

    self._headRender = HeadRender.create(self._ui.head, 3)
    self:refresh()
end

function ClassRef:refresh()
    local hasData = self._data ~= nil
    self._ui.unknown:setVisible(not hasData)
    self._headRender:setVisible(hasData)
    self._ui.name:setVisible(hasData)
    self._ui.duty:setVisible(hasData)
    self._ui.tips:setVisible(not hasData)
    if hasData then
        local avatarParams = self._data:getAvatarParams()
        self._headRender:setData(avatarParams)
        self._ui.name:setString(avatarParams.name)
        self._ui.duty:setString(self._data:getDuty())
    end
end

function ClassRef:setIsNew(b)
    self._ui.selected:setVisible(b)
    self._ui.icon_new:setVisible(b)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
